package com.hsteach.web.controller.common;

import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.model.AuthInfo;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.exception.ServiceException;
import com.hsteach.common.utils.DateUtils;
import com.hsteach.common.utils.SecurityUtils;
import com.hsteach.framework.feign.client.xgk.dto.GetOrganPersonListEntity;
import com.hsteach.framework.feign.client.xgk.dto.GetStudentListByGradeAndClassEntity;
import com.hsteach.framework.feign.client.xgk.dto.ret.*;
import com.hsteach.framework.web.service.AuthService;
import com.hsteach.service.cookmenu.CookmenuWeekService;
import com.hsteach.service.third.XgkService;
import com.hsteach.util.BuildingComparator;
import com.hsteach.util.MyPager;
import com.hsteach.web.controller.common.dto.GetByGradeAndClassDto;
import com.hsteach.web.controller.common.dto.GetPersonListByOrgListAndPersonNameDto;
import com.hsteach.web.controller.common.vo.SemMonth;
import com.hsteach.web.controller.cookmenu.vo.SemWeek;
import com.hsteach.web.controller.meeting.dto.GetWeekDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.hsteach.common.config.RuoYiConfig;
import com.hsteach.common.constant.Constants;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.utils.StringUtils;
import com.hsteach.common.utils.file.FileUploadUtils;
import com.hsteach.common.utils.file.FileUtils;
import com.hsteach.framework.config.ServerConfig;

/**
 * 通用请求处理
 *
 * @author ruoyi
 */
@Api(value = "公共接口", tags = "公共接口")
@RestController
@RequestMapping("/common")
public class CommonController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(CommonController.class);

    @Autowired
    private ServerConfig serverConfig;

    private static final String FILE_DELIMETER = ",";

    @Autowired
    private XgkService xgkService;

    @Autowired
    private CookmenuWeekService cookmenuWeekService;

    @Autowired
    private AuthService authService;

    /**
     * 通用下载请求
     *
     * @param fileName 文件名称
     * @param delete 是否删除
     */
    @ApiOperation("通用下载请求")
    @GetMapping("/download")
    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
    {
        try
        {
            if (!FileUtils.checkAllowDownload(fileName))
            {
                throw new Exception(StringUtils.format("文件名称({})非法，不允许下载。 ", fileName));
            }
            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
            String filePath = RuoYiConfig.getDownloadPath() + fileName;

            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            FileUtils.setAttachmentResponseHeader(response, realFileName);
            FileUtils.writeBytes(filePath, response.getOutputStream());
            if (delete)
            {
                FileUtils.deleteFile(filePath);
            }
        }
        catch (Exception e)
        {
            log.error("下载文件失败", e);
        }
    }

    /**
     * 通用上传请求（单个）
     */
    @ApiOperation("通用上传请求（单个）")
    @PostMapping("/upload")
    public AjaxResult uploadFile(MultipartFile file) throws Exception
    {
        try
        {
            // 上传文件路径
            String filePath = RuoYiConfig.getUploadPath();
            // 上传并返回新文件名称
            String fileName = FileUploadUtils.upload(filePath, file);
            String url = serverConfig.getUrl() + fileName;
            AjaxResult ajax = AjaxResult.success();
            ajax.put("url", url);
            ajax.put("fileName", fileName);
            ajax.put("newFileName", FileUtils.getName(fileName));
            ajax.put("originalFilename", file.getOriginalFilename());
            return ajax;
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 通用上传请求（多个）
     */
    @ApiOperation("通用上传请求（多个）")
    @PostMapping("/uploads")
    public AjaxResult uploadFiles(List<MultipartFile> files) throws Exception
    {
        try
        {
            // 上传文件路径
            String filePath = RuoYiConfig.getUploadPath();
            List<String> urls = new ArrayList<String>();
            List<String> fileNames = new ArrayList<String>();
            List<String> newFileNames = new ArrayList<String>();
            List<String> originalFilenames = new ArrayList<String>();
            for (MultipartFile file : files)
            {
                // 上传并返回新文件名称
                String fileName = FileUploadUtils.upload(filePath, file);
                String url = serverConfig.getUrl() + fileName;
                urls.add(url);
                fileNames.add(fileName);
                newFileNames.add(FileUtils.getName(fileName));
                originalFilenames.add(file.getOriginalFilename());
            }
            AjaxResult ajax = AjaxResult.success();
            ajax.put("urls", StringUtils.join(urls, FILE_DELIMETER));
            ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER));
            ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER));
            ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));
            return ajax;
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 本地资源通用下载
     */
    @ApiOperation("本地资源通用下载")
    @GetMapping("/download/resource")
    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
            throws Exception
    {
        try
        {
            if (!FileUtils.checkAllowDownload(resource))
            {
                throw new Exception(StringUtils.format("资源文件({})非法，不允许下载。 ", resource));
            }
            // 本地资源路径
            String localPath = RuoYiConfig.getProfile();
            // 数据库资源地址
            String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
            // 下载名称
            String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
            response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
            FileUtils.setAttachmentResponseHeader(response, downloadName);
            FileUtils.writeBytes(downloadPath, response.getOutputStream());
        }
        catch (Exception e)
        {
            log.error("下载文件失败", e);
        }
    }



    /**
     * 根据buildingId查询子树信息
     * @param buildingId
     * @return
     */
    @ApiOperation("根据buildingId查询子树信息")
    @PostMapping("/getPlaceChildrenTree")
    public AjaxResult getPlaceChildrenTree(@RequestParam String buildingId){
        return success(xgkService.getPlaceChildrenTree(buildingId));
    }

    /**
     * 获取场所树
     * @param
     * @return
     */
    @ApiOperation("获取场所树")
    @GetMapping("/getPlaceTree")
    public AjaxResult getPlaceTree(){
        GetPlaceChildrenTreeRet ret = xgkService.getPlaceTree();
        //去除没有房间的建筑和楼层
        excludeBlankBuildingsAndFloors(ret);
        if (!ret.getChildren().isEmpty() && ret.getBuildingType()<3){//递归排序
            sortBuilding(ret.getChildren());
        }
        return success(ret);
    }

    //排序
    private void sortBuilding(List<GetPlaceChildrenTreeRet> childrenList){
        childrenList.sort(new BuildingComparator());
        for (GetPlaceChildrenTreeRet r : childrenList){
            if (!r.getChildren().isEmpty() && r.getBuildingType()<3){
                sortBuilding(r.getChildren());
            }
        }
    }

    /**
     * 去除没有房间的建筑和楼层
     * 使用deleteList删除集合保存待删除节点，防止ConcurrentModificationException异常
     * 强烈警告：屎山代码，请勿乱动，不然我就要屎了！！！！！！！！！！！！！！！！！！！！！！！！
     * @param school 场所树顶层节点(学校节点)
     */
    private void excludeBlankBuildingsAndFloors(GetPlaceChildrenTreeRet school) {
        //school不是顶级节点或学校为空或者学校的校区为空
        if (!school.getBuildingType().equals(0) || ObjectUtils.isEmpty(school) || ObjectUtils.isEmpty(school.getChildren())) {
            return;
        }
        //获取学校的校区集合
        List<GetPlaceChildrenTreeRet> campus = school.getChildren();
        //遍历校区
        for (GetPlaceChildrenTreeRet campusNode : campus) {
            //获取校区的建筑
            List<GetPlaceChildrenTreeRet> buildingsList = campusNode.getChildren();
            Map<String, GetPlaceChildrenTreeRet> treeBuildingsList = campusNode.getTreeChildren();
            //校区的建筑不为空
            if (!ObjectUtils.isEmpty(buildingsList)) {
                //待删除建筑节点和ID集合
                List<GetPlaceChildrenTreeRet> deleteBuildingList = new ArrayList<>();
                List<String> deleteBuildingIdList = new ArrayList<>();
                //遍历建筑
                for (GetPlaceChildrenTreeRet buildingNode : buildingsList) {
                    //当前建筑的楼层集合
                    List<GetPlaceChildrenTreeRet> floorList = buildingNode.getChildren();
                    Map<String, GetPlaceChildrenTreeRet> treeFloorList = buildingNode.getTreeChildren();
                    if (ObjectUtils.isEmpty(floorList)) {
                        //楼层为空，则移除当前建筑
                        deleteBuildingList.add(buildingNode);
                        deleteBuildingIdList.add(buildingNode.getBuildingId());
                        continue;
                    }
                    //计算当前建筑下的所有楼层的房间数量的总和
                    int roomCountOfBuilding = calculateRoomNumOfBuilding(buildingNode);
                    //当前建筑的所有楼层都没有房间，移除此建筑
                    if (roomCountOfBuilding <= 0) {
                        deleteBuildingList.add(buildingNode);
                        deleteBuildingIdList.add(buildingNode.getBuildingId());
                        continue;
                    }
                    //待删除楼层节点和ID集合
                    List<GetPlaceChildrenTreeRet> deleteFloorList = new ArrayList<>();
                    List<String> deleteFloorIdList = new ArrayList<>();
                    //当前建筑有房间，则依次判断楼层
                    for (GetPlaceChildrenTreeRet floorNode : floorList) {
                        //计算当前楼层的房间数量
                        int roomNumOfFloor = calculateRoomNumOfFloor(floorNode);
                        if (roomNumOfFloor <= 0) {
                            //当前楼层不存在房间,移除楼层
                            deleteFloorList.add(floorNode);
                            deleteFloorIdList.add(floorNode.getBuildingId());
                        }
                    }
                    floorList.removeAll(deleteFloorList);
                    //移除TreeNode的数据  //！！！！！！
                    for (String deleteFloorId : deleteFloorIdList) {
                        if (!CollectionUtils.isEmpty(treeFloorList)) {
                            treeFloorList.remove(deleteFloorId);
                        }
                    }
                }
                buildingsList.removeAll(deleteBuildingList);
                //移除TreeNode的数据  //！！！！！！！！
                for (String deleteBuildingId : deleteBuildingIdList) {
                    if (!CollectionUtils.isEmpty(treeBuildingsList)) {
                        treeBuildingsList.remove(deleteBuildingId);
                    }
                }
            }
            //校区的建筑为空则跳过，继续执行
        }
    }

    /**
     * 计算楼层具有的房间数
     * @return 楼层的房间数
     */
    private int calculateRoomNumOfFloor(GetPlaceChildrenTreeRet floor) {
        //当前楼层不存在，或者楼层无房间
        if (ObjectUtils.isEmpty(floor) || ObjectUtils.isEmpty(floor.getChildren())) {
            return 0;
        }
        return floor.getChildren().size();
    }

    /**
     * 计算建筑下所有楼层的房间总数
     * @param building 建筑
     * @return 建筑下的所有楼层的房间总数
     */
    private int calculateRoomNumOfBuilding(GetPlaceChildrenTreeRet building) {
        int sum = 0;
        //当前建筑不存在，或者建筑无楼层
        if (ObjectUtils.isEmpty(building) || ObjectUtils.isEmpty(building.getChildren())) {
            return 0;
        }
        //当前建组的楼层集合
        List<GetPlaceChildrenTreeRet> floorList = building.getChildren();
        for (GetPlaceChildrenTreeRet floorNode : floorList) {
            sum += calculateRoomNumOfFloor(floorNode);
        }
        return sum;
    }

    /**
     * 根据（校区、楼栋、楼层，均可空）获取教室列表
     * @param type
     * @param buildingId
     * @return
     */
    @ApiOperation("根据（校区、楼栋、楼层，均可空）获取教室列表")
    @PostMapping("/getClassRoomListByPlaceId")
    public AjaxResult getClassRoomListByPlaceId(@RequestParam("type") Integer type,@RequestParam("buildingId") String buildingId){
        return success(xgkService.getClassRoomListByPlaceId(type,buildingId).stream()
                .sorted(Comparator.comparingInt(room -> Integer.parseInt(room.getRoomCode())))
                .collect(Collectors.toList()));
    }


    /**
     * 查询机构所有用户 有缓存
     * @return
     */
    @ApiOperation("查询机构所有用户 有缓存")
    @GetMapping("/getAllUsers")
    public AjaxResult getAllUsers(@RequestParam(value = "orgCode",required = false) String orgCode){
        if (ObjectUtils.isEmpty(orgCode)){
            orgCode = SecurityUtils.getAuthInfo().getOrgCode();
        }
        return success(xgkService.getAllUsers(orgCode));
    }

    /**
     * 获取部门组织树
     * @param orgCode
     * @return
     */
    @ApiOperation("获取部门组织树")
    @GetMapping("/getAdmOrgTreed")
    public AjaxResult getAdmOrgTreed(@RequestParam(value = "orgCode",required = false) String orgCode){
        if (ObjectUtils.isEmpty(orgCode)){
            /*orgCode = SecurityUtils.getAuthInfo().getOrgCode();*/
        }
        return success(xgkService.getAdmOrgTreed(orgCode,"administration"));
    }

    /**
     * 获取部门组织下人员列表
     * @param orgCode
     * @return
     */
    @ApiOperation("获取部门组织下人员列表")
    @PostMapping("/getAdmBraPerList")
    public AjaxResult getAdmBraPerList(@RequestParam(value = "orgCode",required = false) String orgCode,@RequestParam(value = "name",required = false) String name){
        if (ObjectUtils.isEmpty(orgCode)){
            orgCode = SecurityUtils.getAuthInfo().getOrgCode();
        }
        return success(xgkService.getAdmBraPerList(orgCode,"administration",name));
    }

    /**
     * 通过机构列表和人员名称查询人员列表(分页)
     * @param dto
     * @return
     */
    @ApiOperation("通过机构列表和人员名称查询人员列表(分页)")
    @PostMapping("/getPersonListByOrganListWithPages")
    public AjaxResult getPersonListByOrganListWithPages(@RequestBody GetPersonListByOrgListAndPersonNameDto dto){
        return success(xgkService.getPersonListByOrganListWithPages(dto));
    }

    @ApiOperation("获取教学机构树")
    @GetMapping("getTeaOrgTree")
    public AjaxResult getTeaOrgTree(){
        return success(xgkService.getTeaOrgTree());
    }


    @ApiOperation("获取教学机构人员信息")
    @PostMapping("getOrganPersonList")
    public AjaxResult getOrganPersonList(@RequestBody GetOrganPersonListEntity getOrganPersonListEntity){
        AuthInfo authInfo = SecurityUtils.getAuthInfo();
        if (authInfo.getOrgCode().equals(getOrganPersonListEntity.getGroupId())) {
            List<GetTeacherRet> teachers = xgkService.getTeachers(authInfo.getOrgCode());
            List<GetOrganPersonListRet> list = teachers.stream().map(e -> {
                GetOrganPersonListRet ret = new GetOrganPersonListRet();
                BeanUtils.copyProperties(e, ret);
                ret.setSex("XB_1".equals(e.getSex()) ? "男" : "女");
                if (!CollectionUtils.isEmpty(e.getJobList())) {
                    String collect = e.getJobList().stream().map(JobList::getJobName).collect(Collectors.joining(","));
                    ret.setDutyName(collect);
                }
                return ret;
            }).collect(Collectors.toList());
            Map<String, Object> map = new HashMap<>();
            if (StringUtils.isNotEmpty(getOrganPersonListEntity.getName())) {
                list = list.stream().filter(e ->
                    Optional.ofNullable(e.getName()).orElse("").contains(getOrganPersonListEntity.getName())).collect(Collectors.toList());
            }
            map.put("list", list);
            return success(map);
        }
        return success(xgkService.getOrganPersonList(getOrganPersonListEntity));
    }

    @ApiOperation("获取学年学期列表")
    @GetMapping("getYearList")
    public AjaxResult getYearList(){
        boolean selected = false;
        Integer yearIndex = null;
        Integer nearestIndex = null;
        Long nearestDif = null;
        // 根据当前时间将对应节点添加选中标记，如果没有符合的日期，则选中最近的未来节点
        List<GetYearListRet> yearList = xgkService.getYearList(SecurityUtils.getAuthInfo().getOrgCode());
        for (int j = 0; j< yearList.size(); j++) {
            GetYearListRet year = yearList.get(j);
            String beginDay = year.getBeginDay();
            String endDay = year.getEndDay();
            if (StringUtils.isNotEmpty(beginDay) && StringUtils.isNotEmpty(endDay)) {
                Date begin = DateUtils.parseDate(beginDay);
                Date end = DateUtils.parseDate(endDay);
                long now = System.currentTimeMillis();
                if (now >= begin.getTime() && now <= end.getTime()) {
                    year.setSelected(true);
                    yearIndex = j;
                    for (int i = 0;i < year.getSemAddVacation().size(); i++) {
                        SemAddVacation sem = year.getSemAddVacation().get(i);
                        String semBeginDay = sem.getTeachWeekBeginDay();
                        String semEndDay = sem.getEndDay();
                        if (StringUtils.isNotEmpty(semBeginDay) && StringUtils.isNotEmpty(semBeginDay)) {
                            Date semBegin = DateUtils.parseDate(semBeginDay);
                            Date semEnd = DateUtils.parseDate(semEndDay);
                            if (now >= semBegin.getTime() && now <= semEnd.getTime()) {
                                sem.setSelected(true);
                                selected = true;
                            } else {
                                long dif = getDif(now, semBegin.getTime());
                                if (nearestIndex == null) {
                                    nearestIndex = i;
                                    nearestDif = dif;
                                } else {
                                    if (dif < nearestDif  && now > semBegin.getTime()) {
                                        nearestDif = dif;
                                        nearestIndex = i;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (!selected && nearestIndex != null && yearIndex != null) {
            yearList.get(yearIndex).getSemAddVacation().get(nearestIndex).setSelected(true);
        }
        // 学期重排序
        yearList.stream().forEach(e -> {
            List<SemAddVacation> collect = e.getSemAddVacation().stream().sorted(Comparator.comparing(SemAddVacation::getBeginDay)).collect(Collectors.toList());
            e.setSemAddVacation(collect);
        });

        return success(yearList);
    }

    private long getDif(long n1, long n2) {
        if (n1 > n2) {
            return n1 - n2;
        } else {
            return n2 - n1;
        }
    }


    @ApiOperation("根据起止时间获取周次")
    @PostMapping("/getWeek")
    public TableDataInfo getWeek(@RequestBody GetWeekDto dto)
    {
        if (dto.getBeginDay().getTime() > dto.getEndDay().getTime()) {
            throw new ServiceException("开始时间不能大于结束时间");
        }
        List<SemWeek> list = cookmenuWeekService.getWeekList(dto.getBeginDay(), dto.getEndDay());
        return getDataTable(list);
    }

    @ApiOperation("根据起止时间获取月份")
    @PostMapping("/getMonth")
    public TableDataInfo getMonth(@RequestBody GetWeekDto dto)
    {
        if (dto.getBeginDay().getTime() > dto.getEndDay().getTime()) {
            throw new ServiceException("开始时间不能大于结束时间");
        }
        List<SemMonth> monthList = cookmenuWeekService.getMonthList(dto.getBeginDay(), dto.getEndDay());
        return getDataTable(monthList);
    }

    @ApiOperation("获取所有年级")
    @GetMapping("/getAllGrade")
    public TableDataInfo getAllGrade()
    {
        List<GetSchoolPartTreeRet> allGrade = xgkService.getAllGrade(SecurityUtils.getAuthInfo().getOrgCode());
        return getDataTable(allGrade);
    }

    @ApiOperation("获取学校所班级")
    @GetMapping("/getAllClass")
    public AjaxResult getAllClass(String schoolId)
    {
        GetSchoolPartTreeRet schoolPartTree = xgkService.getClassTreeBySchoolId(SecurityUtils.getAuthInfo().getOrgCode());
        return success(schoolPartTree);
    }

    @ApiOperation("区域根据学校id获取学校所有班级")
    @GetMapping("/getAllClassBySchoolId")
    public AjaxResult getAllClassBySchoolId(String schoolId)
    {
        return success(authService.getAllClassBySchoolId(schoolId));
    }

    @ApiOperation("获取年级下的班级")
    @GetMapping("/getClassByGrade/{unitId}")
    public TableDataInfo getClassByGrade(@PathVariable("unitId") String unitId)
    {
        GetSchoolPartTreeRet classByGrade = xgkService.getClassByGrade(SecurityUtils.getAuthInfo().getOrgCode(), unitId);
        if (classByGrade != null) {
            return getDataTable(classByGrade.getChildren());
        }
        return getDataTable(Lists.newArrayList());
    }

    @ApiOperation("根据班级/年级查询学生")
    @PostMapping("/getStudentListByGradeAndClass")
    public TableDataInfo getStudentListByGradeAndClass(@RequestBody GetByGradeAndClassDto dto)
    {
        GetStudentListByGradeAndClassEntity entity = new GetStudentListByGradeAndClassEntity();
        BeanUtils.copyProperties(dto, entity);
        List<PersonInfoRet> personInfoRets = xgkService.getStudentListByGradeAndClass(entity);
        if (personInfoRets != null) {
            if (StringUtils.isNotEmpty(dto.getSearchName())) {
                personInfoRets = personInfoRets.stream().filter(e ->
                        Optional.ofNullable(e.getName()).orElse("").contains(dto.getSearchName()) ||
                                Optional.ofNullable(e.getSchoolNo()).orElse("").contains(dto.getSearchName()) ||
                                Optional.ofNullable(e.getOrgPartCode()).orElse("").contains(dto.getSearchName())).collect(Collectors.toList());
            }
            TableDataInfo<PersonInfoRet> pageRet = new TableDataInfo<>();
            MyPager pager = new MyPager<>();
            pager.setCurrentPages(dto.getPageNum());
            pager.setSize(dto.getPageSize());
            pager.setDataList(personInfoRets);
            pageRet.setTotal(pager.getRecordCount());
            //获得分页结果
            pageRet.setRows(pager.getResultsList());
            return pageRet;
        }
        return getDataTable(Lists.newArrayList());
    }

    @ApiOperation("根据班级/年级查询教师")
    @PostMapping("/getTeacherListByGradeAndClass")
    public TableDataInfo getTeacherListByGradeAndClass(@RequestBody GetByGradeAndClassDto dto)
    {
        GetStudentListByGradeAndClassEntity entity = new GetStudentListByGradeAndClassEntity();
        BeanUtils.copyProperties(dto, entity);
        List<PersonInfoRet> personInfoRets = xgkService.getTeacherListByGradeAndClass(entity);
        if (personInfoRets != null) {
            if (StringUtils.isNotEmpty(dto.getSearchName())) {
                personInfoRets = personInfoRets.stream().filter(e ->
                        Optional.ofNullable(e.getName()).orElse("").contains(dto.getSearchName()) ||
                                Optional.ofNullable(e.getSchoolNo()).orElse("").contains(dto.getSearchName()) ||
                                Optional.ofNullable(e.getOrgPartCode()).orElse("").contains(dto.getSearchName())).collect(Collectors.toList());
            }
            TableDataInfo<PersonInfoRet> pageRet = new TableDataInfo<>();
            MyPager pager = new MyPager<>();
            pager.setCurrentPages(dto.getPageNum());
            pager.setSize(dto.getPageSize());
            pager.setDataList(personInfoRets);
            pageRet.setTotal(pager.getRecordCount());
            //获得分页结果
            pageRet.setRows(pager.getResultsList());
            return pageRet;
        }
        return getDataTable(Lists.newArrayList());
    }


}
